﻿<phone:PhoneApplicationPage
    x:Class="Example.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:TreeView;assembly=TreeView" xmlns:example="clr-namespace:Example"
    mc:Ignorable="d"
    d:DataContext="{d:DesignInstance example:MainPage}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <phone:PhoneApplicationPage.Resources>
        <example:BoolToOpacityConverter x:Key="BoolToOpacityConverter"/>
    </phone:PhoneApplicationPage.Resources>
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <StackPanel>
           
            <Button Click="Add_Click">Add Animal</Button>
            <Button Click="ExpandTo_Click">Expand to Lion</Button>
            <CheckBox IsChecked="{Binding ElementName=TreeViewControl, Path=IsSelected, Mode=TwoWay}">Tree</CheckBox>
        </StackPanel>

        <controls:TreeView x:Name="TreeViewControl"
                           Grid.Row="1"
                           SelectedItem="{Binding Tree.SelectedCategory, Mode=TwoWay}"
                           ItemsSource="{Binding Tree.Categories}"
                           ScrollViewer.VerticalScrollBarVisibility="Visible"
                           ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                           SubItemsSource="{Binding SubCategories}">
            <controls:TreeView.HeaderTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="5,0,0,0" >
                        <Path x:Name="CheckMark" Data="M0,123 L39,93 L124,164 L256,18 L295,49 L124,240 z" 
                              Fill="{StaticResource PhoneAccentBrush}"
                              FlowDirection="LeftToRight" HorizontalAlignment="Center" Height="20"
                              IsHitTestVisible="False" Stretch="Fill" StrokeThickness="3" 
                              StrokeLineJoin="Round"
                              Opacity="{Binding IsCategorySelected, Converter={StaticResource BoolToOpacityConverter}}" 
                              VerticalAlignment="Center" Width="20"/>
                        <TextBlock x:Name="txtName" Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}"/>
                    </StackPanel>
                </DataTemplate>
            </controls:TreeView.HeaderTemplate>
        </controls:TreeView>


    </Grid>

</phone:PhoneApplicationPage>